package com.example.imooc_utils.lambda.file;

import java.io.*;

/**
 * @author lxp
 * @program imooc_utils
 * @description 函数式编程实例文件服务类
 * @create: 2019-12-25 15:50
 */
public class FileService {

    public void fileHandle(String url , FileConsumer fileConsumer) throws IOException {

        // 创建文件读取流
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(
                        new FileInputStream(url)));

        // 定义行变量和内容
        String line;
        StringBuilder stringBuilder = new StringBuilder();
        while((line = bufferedReader.readLine())!=null){
            stringBuilder.append(line + "\n");
        }

        // 调用函数式接口方法 ，将文件内容传递给lambda表达式
        fileConsumer.fildHandler(stringBuilder.toString());
    }
}
